import os
import sys
import json
from optparse import OptionParser
from pprint import pprint
from repository.store_repository import *
from entity.item_entity import *

db = StoreRepository() 

db_name = db.getDatabase()
table_name = db.getTable()

def itemImport():

	print "Importing Item data for item.json"

	#db = ItemRepository()
	item_data = open('import/item.json')
	item_json = json.load(item_data)

	for id in item_json:
		import_entity = ItemEntity()
		import_entity.setItemName(str(item_json[id]['item_name']))
		import_entity.setDepartmentId(int(item_json[id]['department_id']))
		import_entity.setPrice(float(item_json[id]['price']))
		import_entity.setQuantity(int(item_json[id]['quantity']))

		print "---" + import_entity.getItemName() + "---"
		print import_entity.getDepartmentId()
		print import_entity.getPrice()
		print import_entity.getQuantity()

def storeImport():
	print "Importing Store data from store.json"

def cartImport():
	print "Importing Cart data from cart.json"

def customerImport():
	print "Importing Customer data from customer.json"

def allImport():
	itemImport()
	storeImport()
	cartImport()
	customerImport()

try: 

	parser = OptionParser()
	parser.add_option('-c', '--create-scheme', action="store", default="all", help="Create data scheme", metavar="SCHEME NAME")
	parser.add_option('-i', '--initial-import', action="store", default="all", help="Type of data to import", metavar="IMPORT DATA NAME")
	(options, args) = parser.parse_args()

	initial_import = options.initial_import
	
	if initial_import == 'item':
		itemImport()
	elif initial_import == 'store':
		storeImport()
	elif initial_import == 'cart':
		cartImport()
	elif initial_import == 'customer':
		customerImport()
	else:
		allImport()

	#createScheme()	
	#dataImport()



except Exception as e:
	print e
	sys.exit(-1)



